import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * model 集团
 * @date: 2018-7-16


 */
import { getResponse } from 'utils/utils';
import { fetchGroup as _fetchGroup, updateGroup as _updateGroup } from "../services/groupService";
export default {
  namespace: 'group',
  state: {
    groupData: []
  },
  effects: {
    // 获取集团信息
    fetchGroup: /*#__PURE__*/_regeneratorRuntime.mark(function fetchGroup(_ref, _ref2) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function fetchGroup$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              _context.next = 4;
              return call(_fetchGroup, payload);

            case 4:
              res = _context.sent;
              list = getResponse(res);

              if (!list) {
                _context.next = 9;
                break;
              }

              _context.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  groupData: list
                }
              });

            case 9:
              return _context.abrupt("return", list);

            case 10:
            case "end":
              return _context.stop();
          }
        }
      }, fetchGroup);
    }),
    // 更新集团信息
    updateGroup: /*#__PURE__*/_regeneratorRuntime.mark(function updateGroup(_ref3, _ref4) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function updateGroup$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call, put = _ref4.put;
              _context2.next = 4;
              return call(_updateGroup, payload);

            case 4:
              res = _context2.sent;
              list = getResponse(res);

              if (!list) {
                _context2.next = 9;
                break;
              }

              _context2.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  groupData: list
                }
              });

            case 9:
              return _context2.abrupt("return", list);

            case 10:
            case "end":
              return _context2.stop();
          }
        }
      }, updateGroup);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref5) {
      var payload = _ref5.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};